package com.bookshop.vo;

import java.util.ArrayList;

import com.bookshop.promotion.logic.DiscountCoupons;
import com.bookshop.promotion.logic.EqualCoupons;


public class CustomerVO implements ValueObject{
	
	private static final long serialVersionUID = -3524894390408921350L;
	
	public String mAccount;
	public String mPassword;
	public double mCreditPoints;
	public String mName;
	public String mCellNumber;
	public String mAddress;
	private EqualCoupons[] mEqualCoupons;
	private DiscountCoupons[] mDiscountCoupons;
	

	public void update(String pAccount,String pPassword,String pName,String pCellNumber,String pAddress,double pCreditPoints, EqualCoupons[] pEqualCoupons,DiscountCoupons[] pDiscountCoupons){
		mAccount=pAccount;
		mPassword=pPassword;
		mName=pName;
		mCellNumber=pCellNumber;
		mAddress=pAddress;
		mCreditPoints=pCreditPoints;
		mEqualCoupons=pEqualCoupons;
		mDiscountCoupons=pDiscountCoupons;
	}
	
	
	
	public double[] getCoupons(){
		ArrayList<Double> coupons = new ArrayList<>();
		for (int i = 0; i < mEqualCoupons.length; i++) {
			while(mEqualCoupons[i].mCount != 0) {
				coupons.add(mEqualCoupons[i].mPerValue);
				mEqualCoupons[i].mCount--;
			}
		}
		for (int i = 0; i < mDiscountCoupons.length; i++) {
			while(mDiscountCoupons[i].mCount != 0) {
				coupons.add(mDiscountCoupons[i].mCiscountRate);
				mDiscountCoupons[i].mCount--;
			}
		}
		Double[] couponsArray = new Double[coupons.size()];
		couponsArray = coupons.toArray(couponsArray);
		return todouble(couponsArray);
	}
	
	private double[] todouble(Double[] Doubles){
		double[] doubles = new double[Doubles.length];
		for (int i = 0; i < Doubles.length; i++) {
			doubles[i] = Doubles[i].doubleValue();
		}
		return doubles;
	}
}
